package com.xq.jltx.actiontoolsbar;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btn1;
    private Button btn2;
    private Button btn3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle("ActionBar的使用");
        initView();
/*        DisplayMetrics dm = getResources().getDisplayMetrics();
        int barHeight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,56,dm);
        int barHeight1 = dip2px(this,56);
        XqLog.d("TTTTT","barHeight=>"+barHeight);
        XqLog.d("TTTTT","barHeight1=>"+barHeight1);*/
    }

    public  int dip2px(Context context, float dipValue){
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int)(dipValue * scale + 0.5f);
    }

    public  int px2dip(Context context, float pxValue){
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int)(pxValue / scale + 0.5f);
    }

    private void initView(){
        btn1 = (Button)this.findViewById(R.id.btn1);
        btn2 = (Button)this.findViewById(R.id.btn2);
        btn3 = (Button)this.findViewById(R.id.btn3);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()){
            case R.id.btn1:
                intent = new Intent();
                intent.setClass(this,OriginBarActivity.class);
                String text = btn1.getText().toString();
                intent.putExtra("title",text);
                startActivity(intent);
                break;
            case R.id.btn2:
                intent = new Intent();
                intent.setClass(this,CustomBarActivity.class);
                String text1 = btn2.getText().toString();
                intent.putExtra("title",text1);
                startActivity(intent);
                break;
            case R.id.btn3:
                intent = new Intent();
                intent.setClass(this,SimpleToolBarActivity.class);
                String text2 = btn3.getText().toString();
                intent.putExtra("title",text2);
                startActivity(intent);
                break;
            default:
                break;
        }
    }


}
